package com.xidian.zhiancloud.controller.systemset;

import com.github.pagehelper.Page;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.syset.SysAnnouncement;
import com.xidian.zhiancloud.qo.BaseReqQuery;
import com.xidian.zhiancloud.service.user.IAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统设置-系统公告
 */
@RestController
@RequestMapping("/announ")
public class AnnouncementController extends BaseController {

    @Autowired
    private IAnnouncementService announcementService;

    /**
     * 显示
     * @param
     *
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/getAnnouncementList")
    public ResultDTO getAnnouncementList (BaseReqQuery reqdata) {
        Page<SysAnnouncement> pagedata = announcementService.
                getAnnouncementList(this.getSessionUserCompanyId(),reqdata);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("datalist", pagedata);
        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除
     * @param id 相关公告ID
     * @return 返回ResultDTO对象
     */
    @RequestMapping("/deleteAnnouncement")
    public ResultDTO deleteAnnouncement(@RequestParam("id") String id) {
        announcementService.removeAnnouncement(id);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 查看
     *
     * @param id 相关公告ID
     * @return 返回ResultDTO对象
     */
    @RequestMapping("/updateAnnouncement")
    public ResultDTO updateAnnouncement(@RequestParam("id") String id) {
        return ResultDTO.successOf(announcementService.
                selectByAnnouncement(id),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 添加
     * @param announcement 相关公告对象
     * @return ResultDTO对象
     */ 
    @RequestMapping("/addAnnouncement")
    public ResultDTO addAnnouncement(SysAnnouncement announcement) {
        announcement.setCompanyId(this.getSessionUserCompanyId());
        announcementService.addAnnouncement(announcement);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }


}
